package com.hfb.mashibing.alip8.juc.c020;


import java.util.concurrent.TimeUnit;

/**
 * 可重入锁
 */
public class T01_ReentrantLock1 {
    synchronized void m() {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i);

            if (3 == i) n();
        }
    }
    /*synchronized*/ void n() {
        System.out.println("n。。。");
    }

    public static void main(String[] args) {
        T01_ReentrantLock1 lock = new T01_ReentrantLock1();
        new Thread(lock::m).start();

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(lock::n).start();

    }

}
